import Redis from 'redis';
import env from '../config/env';

const redis = Redis.createClient(env('REDIS_PORT'), env('REDIS_HOST'), {
    prefix: env('REDIS_DATABASE')
});

redis.on('error', function (err) {
    console.log('Error ' + err);
});

redis.on('ready', function () {
    console.log('redis is connect ok');
});
export default {
    async get (key) {
        return await new Promise((resolve, reject) => {
            redis.get(key, (err, data) => {
                if (err) {
                    return reject(err);
                }
                return resolve(data);
            });
        });
    },
    set: (key, value, time) => {
        return redis.set(key, value, 'EX', time);
    },
    has: (key) => {

    }
};